<?php 

class Mahasiswa extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('mahasiswa_model');
	}
	
	function index()
	{	
		if($this->session->userdata('logged_in_jtk'))
		{
			$session_data = $this->session->userdata('logged_in_jtk');
			$data['title'] = "Data Mahasiswa";
			$data['username'] = $session_data['username'];
			$data['menu'] = 2;
			$data['login'] = 1;
			$data['anggota_data'] = $this->mahasiswa_model->get_all_data();
			$data['jum_anggota'] = $this->mahasiswa_model->get_jum_data();		
			$data['act'] = 'well';
			//$this->load->view('header_view', $data);   
			$this->load->view('header_view');
			$this->load->view('mahasiswa_view', $data);
		}
		else
		{
			//If no session, redirect to login page
			//redirect('home', 'refresh');
			//$data['username'] = "teu login";
			$data['username'] = "";
			$data['menu'] = 0;
			$data['login'] = 0;
			$this->load->view('home_view', $data);
		}		
	}
	
	function add()
	{
		$data['title'] = "Tambah Data Mahasiswa";
		$data['menu'] = 2;
		$data['act'] = 'add';
		$this->load->view('header_view');
		$this->load->view('mahasiswa_view', $data);
	}
	
	function insert(){
		$data = array(
			'nim' => $this->input->post('nim'), 			
			'nama' => $this->input->post('nama'), 
			'hp' => $this->input->post('hp'),
			'email' => $this->input->post('email')
		);
		$this->mahasiswa_model->tambah($data);
		redirect('mahasiswa');
	}
	
	function edit()
	{
		$nim = $this->uri->segment(3);
		$data['title'] = "Edit Data Mahasiswa";
		$data['menu'] = 2;
		$data['act'] = 'edit';
		$data['data_edit'] = $this->mahasiswa_model->per_id($nim);
		$this->load->view('mahasiswa_view',$data);
	}
	
	function update()
	{
		$nim = $this->input->post('nim');
		$data = array(			
			'nama' => $this->input->post('nama'), 
			'hp' => $this->input->post('hp'),
			'email' => $this->input->post('email')
		);
		$this->mahasiswa_model->update($nim,$data);		
		redirect('mahasiswa');
	}
	
	function hapus()
	{
		$nim = $this->uri->segment(3);
		$this->mahasiswa_model->hapus($nim);				
		redirect('mahasiswa');
	}
}

?>